package com.yy.anno2;

import java.lang.reflect.Method;

@Pro(className = "com.yy.anno2.Dog", methodName = "show")
public class AnnoTest {
    public static void main(String[] args) throws Exception{
        //获取测试类的Class类型的对象
        Class<AnnoTest> annoTestClass = AnnoTest.class;
        //通过反射 获取当前类的注解
        Pro anno = annoTestClass.getAnnotation(Pro.class);
        
        //获取注解中className属性的值
        String className = anno.className();
        System.out.println("className = " + className);
        String methodName = anno.methodName();
        System.out.println("'methodName' = " + methodName);

        //得到了类名和方法名
        //利用反射实例化对象，并执行方法
        Class<?> aClass = Class.forName(className);

        Object o = aClass.newInstance();
        //获取方法实例
        Method method = aClass.getMethod(methodName);
        //方法调用
        method.invoke(o);


    }
}
